package com.heima.common.OcrUtil;


import com.heima.common.util.OcrUtil;
import net.sourceforge.tess4j.TesseractException;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.IOException;

@RestController
public class TestController {

    @PostMapping("test")
    public String testing(MultipartFile multipartFile) throws IOException, TesseractException {
        byte[] bytes = multipartFile.getBytes();
        ByteArrayInputStream image = new ByteArrayInputStream(bytes);
        BufferedImage read = ImageIO.read(image);

        String s = OcrUtil.doOcr(read);
        System.out.println(s);

        return s;
    }
}
